import { defineStore } from "pinia";
import { ref } from "vue";

// 金泰EAM存储数据
export const useEamStore = defineStore("eam", () => {
  // state
  // 设备选择数据
  const deviceList = ref(uni.getStorageSync("deviceList") || "[]");
  // 点检项数据
  const pointList = ref(uni.getStorageSync("pointList") || "[]");
  // 位置选择数据
  const selectedPosition = ref(uni.getStorageSync("selectedPosition") || "{}");

  // 磨具入库 指导书数据
  const guideBookData = ref(uni.getStorageSync("guideBookData") || "{}");
  // 磨具入库 磨具数据
  const moldData = ref(uni.getStorageSync("moldData") || "{}");
  // action
  /**
   * 设置设备选择数据
   */
  function setDeviceList(data = "") {
    deviceList.value = data ? JSON.stringify([data]) : "[]";
    uni.setStorageSync("deviceList", deviceList.value);
  }
  /**
   * 设置点检项数据
   */
  function setPointList(data = "") {
    pointList.value = data ? JSON.stringify([data]) : "[]";
    uni.setStorageSync("pointList", pointList.value);
  }
  /**
   * 位置设备选择数据
   */
  function setSelectedPosition(data) {
    selectedPosition.value = data ? JSON.stringify(data) : "{}";
    uni.setStorageSync("selectedPosition", selectedPosition.value);
  }

  // 磨具入库 指导书数据
  function setGuideBookData(data) {
    guideBookData.value = data ? JSON.stringify(data) : "{}";
    uni.setStorageSync("guideBookData", guideBookData.value);
  }
  // 磨具入库 模具数据
  function setMoldDataData(data) {
    moldData.value = data ? JSON.stringify(data) : "{}";
    uni.setStorageSync("moldData", moldData.value);
  }
  return {
	  moldData,
	  setMoldDataData,
    deviceList,
    setDeviceList,
    pointList,
    setPointList,
    selectedPosition,
    setSelectedPosition,
    guideBookData,
    setGuideBookData,
  };
});
